unit Class_Levl;

interface
uses
  Classes,SysUtils,Uni,UniEngine;

type
  TLevl=class(TUniEngine)
  public
    LEVL_IDEX: Integer;
    LEVL_PREV: Double;
    LEVL_NEXT: Double;
    LEVL_NAME: string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    class function ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class function CopyIt(ALevl:TLevl):TLevl;        
  end;

implementation

{ TLevl }
procedure TLevl.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('LEVL_IDEX').Value := LEVL_IDEX;
        ParamByName('LEVL_PREV').Value := LEVL_PREV;
        ParamByName('LEVL_NEXT').Value := LEVL_NEXT;
        ParamByName('LEVL_NAME').Value := LEVL_NAME; 
      end;
      otEdit:
      begin
        ParamByName('LEVL_IDEX').Value := LEVL_IDEX;
        ParamByName('LEVL_PREV').Value := LEVL_PREV;
        ParamByName('LEVL_NEXT').Value := LEVL_NEXT;
        ParamByName('LEVL_NAME').Value := LEVL_NAME; 
      end;  
      otDelt:
      begin
        ParamByName('LEVL_IDEX').Value := LEVL_IDEX;
 
      end;  
    end;
  end;
end;

function TLevl.CheckExist(AUniConnection: TUniConnection): Boolean;
begin

end;

function TLevl.GetNextIdex: Integer;
begin

end;

function TLevl.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TLevl.GetStrDelete: string;
begin
  Result:='DELTE FROM TBL_LEVL WHERE 1=1 AND LEVL_IDEX:=LEVL_IDEX';
end;

function TLevl.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_LEVL (LEVL_IDEX,LEVL_PREV,LEVL_NEXT,LEVL_NAME) VALUES (:LEVL_IDEX,:LEVL_PREV,:LEVL_NEXT,:LEVL_NAME)';
end;

function TLevl.GetStrsIndex: string;
begin
  Result:=Format('%D-%F',[LEVL_IDEX,LEVL_PREV]);
end;

function TLevl.GetStrUpdate: string;
begin
  Result:='UPDATE TBL_LEVL SET LEVL_PREV=:LEVL_PREV,LEVL_NEXT=:LEVL_NEXT,LEVL_NAME=:LEVL_NAME, WHERE 1=1 AND  LEVL_IDEX=:LEVL_IDEX';
end;

class function TLevl.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TLevl.Create;
  with TLevl(Result) do
  begin
    LEVL_IDEX:=AUniQuery.FieldByName('LEVL_IDEX').AsInteger;
    LEVL_PREV:=AUniQuery.FieldByName('LEVL_PREV').AsFloat;
    LEVL_NEXT:=AUniQuery.FieldByName('LEVL_NEXT').AsFloat;
    LEVL_NAME:=AUniQuery.FieldByName('LEVL_NAME').AsString;
  end;  
end;

class function TLevl.CopyIt(ALevl: TLevl): TLevl;
begin
  Result:=TLevl.Create;
  Result.LEVL_IDEX:=ALevl.LEVL_IDEX;
  Result.LEVL_PREV:=ALevl.LEVL_PREV;
  Result.LEVL_NEXT:=ALevl.LEVL_NEXT;
  Result.LEVL_NAME:=ALevl.LEVL_NAME;
end;

end.

